﻿@model ForumEditModel
@{
    var title = Resources.EnetaMvc.EditForum;
    if (Model.Forum == null || Model.Forum.Id == 0)
    {
        title = Resources.EnetaMvc.AddForum;
    } 
    
    ViewBag.Title = title;
    Layout = "~/Views/Shared/_ForumsLayout.cshtml";
}
@section Title {
    @title
}
@section Header {
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#selectUserField").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        type: "GET",
                        contentType: "application/json; charset=utf-8",
                        url: "@Url.Action("GetUserNamesAutoComplete")",
                        data: "{'id':'" + document.getElementById('selectUserField').value + "'}",
                        dataType: "json",
                        success: function (data) {
                            response(data);
                        },
                        error: function (result) {
                            alert("Error");
                        }
                    });
                }
            });

            $("#selectUserCommand").click(function() {
                var userNameField = document.getElementById('selectUserField');
                var userName = userNameField.value;

                if (userName == '' || userName == null)
                    return;

                var exists = false;
                $('#ModeratorList option').each(function () {
                    if (this.text == userName) {
                        exists = true;
                        return false;
                    }
                });

                if (exists)
                    return;

                $("#ModeratorList").append('<option>' + userName + '</option>');
            });

            $("#removeUserCommand").click(function () {
                $("#ModeratorList option:selected").remove();
            });

            $("#EditForm").submit(function () {
                $('#ModeratorList option').attr('selected', 'selected');
            });
        });
    </script>        
}

<style>
.content-txt
{
    background-color: #FFF;    
}
.information-main
{
    float:left;    
    margin-left: 15px;
}
</style>
@Html.ValidationSummary(false)

@{ Html.BeginForm("EditForum","Forums",FormMethod.Post,new { id="EditForm" }); }
@Html.HiddenFor(m => m.Forum.Id)
<div class="enter-information">
    <fieldset>
        <div class="input-holder">
            <div class="info-row">
				@Html.ValidationMessageFor(m => m.Forum.Name)
				<div class="title">
					<h5>@Resources.EnetaMvc.ForumTitle</h5>
				</div>
				<div class="error-note"> <span>*</span> </div>
				<div class="information-main">
                    @Html.TextBoxFor(m => m.Forum.Name, new Dictionary<string,object> { {"class","text-go"} })
                </div>
			</div>
            <div class="info-row">
				@Html.ValidationMessageFor(m => m.Forum.Name)
				<div class="title">
					<h5>@Resources.EnetaMvc.ForumCategory</h5>
				</div>
				<div class="error-note"> <span>*</span> </div>
				<div class="information-main">
                    @Html.DropDownListFor(m => m.Forum.CategoryId, Model.Categories)
                </div>
			</div>
            <div class="info-row">
				@Html.ValidationMessageFor(m => m.Forum.Description)
				<div class="title">
					<h5>@Resources.EnetaMvc.ForumDescription</h5>
				</div>
				<div class="error-note"> </div>
				<div class="information-main">
                    @Html.TextAreaFor(m => m.Forum.Description)
                </div>
			</div>
            <div class="info-row">
				@Html.ValidationMessageFor(m => m.Forum.Moderators)
				<div class="title">
					<h5>@Resources.EnetaMvc.ForumModerators</h5>
				</div>
				<div class="error-note"> </div>
				<div class="information-main">
                    <p style="clear: both; display:block">
                        <input type="text" id="selectUserField" /> 
                        <input type="button" id="selectUserCommand" value="Lisa" style="width:40px"/>
                    </p>
                    <p style="clear: both; display:block; vertical-align:top;">
                        <select name="ModeratorList" id="ModeratorList" style="width:200px" multiple="multiple">
                            @if(Model.Moderators != null)
                            {
                                foreach(var moder in Model.Moderators)
                                {
                                    <option>@moder.UserName</option>
                                }
                            }
                        </select>
                        <input type="button" id="removeUserCommand" value="Eemalda" style="width:70px; float:none" />
                    </p>
                </div>
			</div>
            @*<div class="info-row">
				@Html.ValidationMessageFor(m => m.Forum.FeedburnerRssUrl)
				<div class="title">
					<h5>@Resources.EnetaMvc.FeedburnerUrl</h5>
				</div>
				<div class="error-note"> </div>
				<div class="information-main">
                    @Html.TextBoxFor(m => m.Forum.FeedburnerRssUrl, new Dictionary<string, object> { { "class", "text-go" } })
                </div>
			</div>*@
        </div>
        <div class="submit">
			<input type="submit" value="@Resources.EnetaMvc.Save"/>
		</div>
		<a class="loobu" href="@Url.Content("~/forums/")">@Resources.EnetaMvc.Cancel</a>
        <p style="display:block;clear: both">&nbsp;</p>
    </fieldset>
</div>

@{ Html.EndForm(); }